layui.config({
    base: '../../layui/' //此处路径请自行处理, 可以使用绝对路径
}).extend({
    formSelects: 'formSelects-v4'
}).use(['jquery', 'formSelects', 'form','layer'], function () {
    const form = layui.form
        , layer = layui.layer
        , $ = layui.jquery;

    $(function () {
        setTimeout(function() {
            getHst()
        },300)
    })

    function getHst() {
        let params ={
            projectId:$("#projectId").val(),
            namespaceId:$("#namespaceId").val(),
            moduleName:$("#moduleName").val(),
        }
        $.ajax({
            type: "POST",//方法类型
            data: JSON.stringify(params),
            dataType: "json",
            contentType: "application/json;charset=utf-8",
            url: "/admRegistryTagHst/getTagHst",//url
            success: function (result) {
                var html = "";
                if (result.data != null && result.data.length>0) {
                    $.each(result.data, function (index, item) {
                        let content = item.createTime+ "&nbsp;&nbsp;&nbsp;&nbsp;版本号："+item.tag +"&nbsp;&nbsp;&nbsp;";
                        html += "  <li class=\"layui-timeline-item\">\n" +
                            "                <i class=\"layui-icon layui-timeline-axis\"></i>\n" +
                            "                <div class=\"layui-timeline-content layui-text\">\n" +
                            "                    <div class=\"layui-timeline-title\">"+content+ "<a  href=\"javascript:void(0)\"   onclick=\"changeTag("+item.id+")\" id="+item.id+" >  调整更新为此版本</a>"+ "</div>\n" +
                            "                </div>\n" +
                            "            </li>\n";
                    })
                }
                $("#ulId").append(html);

            },
            error: function () {
                alert("异常！");
            }
        });
    }
    window.changeTag =function (id) {
        layer.msg("开始更新版本", {icon: 1, time: 3000}, function () {
            CloseWin();
        })
        const ids = [];
        ids.push($("#id").val())
        let params ={
            tagHstId:id,
            dockerDeployIds:ids,
        }
        $.ajax({
            type: "POST",//方法类型
            data: JSON.stringify(params),
            contentType: "application/json;charset=utf-8",
            dataType: "json",//预期服务器返回的数据类型
            url: "/admDockerDeploy/versionUpdate",//url
            success: function (result) {
                layer.msg("更新完毕", {icon: 1, time: 3000}, function () {

                })
            }
        })
    }
    //关闭页面
    function CloseWin() {
        parent.location.reload(); // 父页面刷新
        const index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
        parent.layer.close(index); //再执行关闭
    }
});

